package wxwoa

import (
	// "log"
	"github.com/kataras/iris/v12"
)

const (
	WX_CACHEKEY_WXCONFIG     = "wx_config"
	WX_CACHEKEY_ACCESS_TOKEN = "wx_access_token"
	WX_CACHEKEY_JSAPI_TICKET = "wx_jsapi_ticket"
	WX_SITE                  = "http://wx.chenrh.com"
	WxTemplateMessagePostURL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
)

func WeChatSubscriptionAppID(ctx iris.Context) string {
	other := ctx.Application().ConfigurationReadOnly().GetOther()
	if id, ok := other["WeChatSubscriptionAppID"].(string); ok {
		return id
	}
	return ""
}
func WeChatSubscriptionAppSecret(ctx iris.Context) string {
	other := ctx.Application().ConfigurationReadOnly().GetOther()
	if id, ok := other["WeChatSubscriptionAppSecret"].(string); ok {
		return id
	}
	return ""
}

// WxConfig 微信公众号结构
type WxConfig struct {
	AppID     string `json:"appid"`
	Timestamp string `json:"timestamp"`
	NonceStr  string `json:"nonceStr"`
	Signature string `json:"signature"`
}

func (c *WxConfig) SaveToCache() {
	if len(c.AppID) == 0 {
		panic("缓存 wx.config 参数失败: appid 为空")
	}
	if len(c.Timestamp) == 0 {
		panic("缓存 wx.config 参数失败: timestamp 为空")
	}
	if len(c.NonceStr) == 0 {
		panic("缓存 wx.config 参数失败: nonceStr 为空")
	}
	if len(c.Signature) == 0 {
		panic("缓存 wx.config 参数失败: signature 为空")
	}

	//
	// log.Println("正在保存 wxconfig 信息到缓存：", c)
	// utils.SetCache(WX_CACHEKEY_WXCONFIG, c, gocache.NoExpiration)
}
